package com.yw.common.core.db.test.jdbctemplate;

import java.lang.reflect.Method;
import java.util.Set;

import com.yw.common.core.db.test.entity.PoStudent;
import com.yw.common.core.util.StringUtil;


public class StudentDao implements IDao<PoStudent>{
	private static String tbName = "student";

	@Override
	public boolean update(PoStudent po, Set<String> fieldSet) {
		String sql = "update " + tbName + " set ";
		Object[] params = new Object[fieldSet.size() + 1];
		JdbcOper jo = new JdbcOper();
		Method m;
		int index = 0;
		Class cls = po.getClass();
		
		try {
			
			for(String s : fieldSet){
				sql += s + "=?,";
					
					
				m = cls.getDeclaredMethod(StringUtil.getGetMethodName(s));
				params[index++] = m.invoke(po);
					
			}
				
			if(sql.charAt(sql.length() - 1) == ','){
				sql = sql.substring(0,sql.length() - 1);
			}
				
			sql += " where id=?";
			m = cls.getDeclaredMethod(StringUtil.getGetMethodName("id"));
			params[index] = m.invoke(po);
		
		}catch (Exception e) {
			e.printStackTrace();
		}

		
		if(-1 == jo.executeUpdate(sql, params)){
			return false;
		}
		return true;
	}	

}
